package com.chensheng.converter;

import com.chensheng.dto.OrderDTO;
import com.chensheng.form.OrderForm;
import com.chensheng.model.OrderDetail;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.List;

/**
 * @Author:ChenSheng
 * @Description:
 * @Date: Created in 上午 10:39 2018/5/15 0015
 */
public class OrderForm2OrderDTO {

    public static OrderDTO convert(OrderForm orderForm){

        OrderDTO orderDTO = new OrderDTO();
        orderDTO.setBuyerName(orderForm.getName());
        orderDTO.setBuyerPhone(orderForm.getPhone());
        orderDTO.setBuyerAddress(orderForm.getAddress());
        orderDTO.setBuyerOpenid(orderForm.getOpenid());

        List<OrderDetail> orderDetailList = new Gson().fromJson(orderForm.getItems(),
                new TypeToken<List<OrderDetail>>(){}.getType());

        orderDTO.setOrderDetailList(orderDetailList);
        return orderDTO;
    }
}
